﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SKYPE4COMLib;
using Org.Mentalis.Utilities;

using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;



namespace GrandmaSkype
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        static public Skype m_Skype = new Skype();
        static Conversion oConvert = new Conversion();
        static String sMyMobileNumber = "+1234567890";
        static Call m_CurrentCall;


        private int userHeight = 0, userWidth = 0;
        private int FixHeight = 1024, FixWidth = 768;
        private System.ComponentModel.Container components = null;

        public Window1()
        {
            Screen Srn = Screen.PrimaryScreen;
            userHeight = Srn.Bounds.Width;
            userWidth = Srn.Bounds.Height;

            InitializeComponent();
            try
            {
                if ((userHeight == 0) || (userWidth == 0))
                {
                    WarningException myEx = new WarningException("Can't change window resolution to 1024x768!");
                    myEx.Source = "GrandmaSkype";
                    myEx.HelpLink = "http://code.google.com/p/grandmaskype/";
                    throw myEx;
                }
                else
                {
                    Resolution.CResolution ChangeRes = new Resolution.CResolution(FixHeight, FixWidth);

                }
            }
            catch (System.Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }


        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if ((userHeight != 0) || (userWidth != 0))
            {
                Resolution.CResolution ChangeRes = new Resolution.CResolution(userHeight, userWidth);
            }

            if (components != null)
            {
                components.Dispose();
            }
        }

        private void CallBegin_Click(object sender, RoutedEventArgs e)
        {

          // Place a call using this Skype object:
          m_CurrentCall = m_Skype.PlaceCall("echo123", "", "", "");
        }

        private void CallEnd_Click(object sender, RoutedEventArgs e)
        {
          // To end a call:
          m_CurrentCall.Finish();
        }


        private void Shutdown_Click(object sender, RoutedEventArgs e)
        {
            //http://www.mentalis.org/soft/class.qpx?id=7
            //WindowsController.ExitWindows(RestartOptions.ShutDown, false);
            Close();
        }

        static void Skype_VoicemailStatus(Voicemail voicemail, TVoicemailStatus status)
        {
            Console.WriteLine(">Voicemail status: " + oConvert.VoicemailStatusToText(status));
            if (status == TVoicemailStatus.vmsDownloading) 
            {
                Console.WriteLine("Sending SMS to " + sMyMobileNumber);
                SmsMessage oMessage = m_Skype.SendSms(sMyMobileNumber, "You have new voicemail from " + voicemail.PartnerDisplayName, "");
            }
        }




    }
}
